home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWSemEvt / FWSemInt.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  22.8 KB  |  708 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWSemInt.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWSEMINT_H
  11. #include "FWSemInt.h"
  12. #endif
  13.  
  14. // ----- Framework Includes -----
  15.  
  16. #ifndef FWACQSCR_H
  17. #include "FWAcqScr.h"
  18. #endif
  19.  
  20. #ifndef FWEXTMGR_H
  21. #include "FWExtMgr.h"
  22. #endif
  23.  
  24. #ifndef FWPART_H
  25. #include "FWPart.h"
  26. #endif
  27.  
  28. #ifndef PRSIGLUE_H
  29. #include "PRSIGlue.h"
  30. #endif
  31.  
  32. #ifndef FWAPLEVT_H
  33. #include "FWAplEvt.h"
  34. #endif
  35.  
  36. #ifndef FWDSCOPR_H
  37. #include "FWDscOpr.h"
  38. #endif
  39.  
  40. #ifndef FWSCPCAL_H
  41. #include "FWScpCal.h"
  42. #endif
  43.  
  44. #ifndef FWSCPCOL_H
  45. #include "FWScpCol.h"
  46. #endif
  47.  
  48. #ifndef FWSCPTBL_H
  49. #include "FWScptbl.h"
  50. #endif
  51.  
  52. #ifndef FWPRTSCP_H
  53. #include "FWPrtScp.h"
  54. #endif
  55.  
  56. #ifndef FWSCPPRP_H
  57. #include "FWScpPrp.h"
  58. #endif
  59.  
  60. #ifndef FWITERS_H
  61. #include "FWIters.h"
  62. #endif
  63.  
  64. #ifndef FWCONTXT_H
  65. #include "FWContxt.h"
  66. #endif
  67.  
  68. #ifndef FWEVENTU_H
  69. #include "FWEventU.h"
  70. #endif
  71.  
  72. #ifndef FWINK_H
  73. #include "FWInk.h"
  74. #endif
  75.  
  76. #ifndef FWOVLSHP_H
  77. #include "FWOvlShp.h"
  78. #endif
  79.  
  80. #ifndef SOM_FW_OSemanticInterface_xh
  81. #include "SLSemInt.xh"
  82. #endif
  83.  
  84. #ifndef FWSOMENV_H
  85. #include "FWSOMEnv.h"
  86. #endif
  87.  
  88. #ifndef FWSESION_H
  89. #include "FWSesion.h"
  90. #endif
  91.  
  92. // ----- OpenDoc Includes -----
  93.  
  94. #ifndef SOM_Module_OpenDoc_StandardExtensions_defined
  95. #include <StdExts.xh>
  96. #endif
  97.  
  98. #ifndef SOM_Module_OpenDoc_ODRegistry_defined
  99. #include <ODRgstry.xh>
  100. #endif
  101.  
  102. #ifndef SOM_ODNameResolver_xh
  103. #include <NamRslvr.xh>
  104. #endif
  105.  
  106. #ifndef SOM_ODObjectSpec_xh
  107. #include <ODObjSpc.xh>
  108. #endif
  109.  
  110. #ifndef SOM_ODOSLToken_xh
  111. #include <ODOSLTkn.xh>
  112. #endif
  113.  
  114. // ----- Macintosh Includes -----
  115.  
  116. #ifndef __ASREGISTRY__
  117. #include <ASRegistry.h>
  118. #endif
  119.  
  120. //========================================================================================
  121. //    Runtime Information
  122. //========================================================================================
  123.  
  124. #ifdef FW_BUILD_MAC    
  125. #pragma segment fwsemevt
  126. #endif
  127.  
  128. FW_DEFINE_AUTO(FW_CSemanticInterface)
  129.  
  130. //========================================================================================
  131. //    class FW_CSemanticInterface
  132. //========================================================================================
  133.  
  134. //---------------------------------------------------------------------------------------
  135. //    FW_CSemanticInterface::FW_CSemanticInterface
  136. //---------------------------------------------------------------------------------------
  137.  
  138. FW_CSemanticInterface::FW_CSemanticInterface(Environment* ev, FW_CPart* part) :
  139.     fDefaultContainer(FW_DYNAMIC_CAST(FW_MPartScriptable, part)),
  140.     fPart(part),
  141.     fOSLFlags(kAEIDoMinimum),
  142.     fUsingPredispatchProc(FALSE)
  143. {
  144. FW_UNUSED(ev);
  145.  
  146.     FW_END_CONSTRUCTOR
  147.     
  148.     // OpenDoc releases 1.0 - 1.04 (possibly later) have a bug that prevents marking 
  149.     // from working correctly. The bug causes OpenDoc to look at the OSL flags of 
  150.     // the part's containing part when determining whether or not a part marks. This 
  151.     // means that if a part says it does marking, OpenDoc will treat it as if it does 
  152.     // not, but will treat all parts contained by that part as if they do.
  153. }
  154.  
  155. //---------------------------------------------------------------------------------------
  156. //    FW_CSemanticInterface::~FW_CSemanticInterface
  157. //---------------------------------------------------------------------------------------
  158.  
  159. FW_CSemanticInterface::~FW_CSemanticInterface()
  160. {
  161.     FW_START_DESTRUCTOR
  162. }
  163.                                                     
  164. //---------------------------------------------------------------------------------------
  165. //    FW_CSemanticInterface::CreateSOMInterface
  166. //---------------------------------------------------------------------------------------
  167.  
  168. FW_OSemanticInterface* FW_CSemanticInterface::CreateSOMInterface(Environment *ev, 
  169.                                                                 FW_CPart *part, 
  170.                                                                 const char *name,
  171.                                                                 void* refCon)
  172. {    
  173. FW_UNUSED(name);
  174. FW_UNUSED(refCon);
  175.     FW_OSemanticInterface* semInt = new FW_OSemanticInterface;
  176.     semInt->InitODFSemanticInterface(ev, part->GetODPart(ev), FW_CSession::GetODSession(ev), this,  FW_PrivGetSemanticInterfaceGlue());
  177.     
  178.     semInt->SetOSLSupportFlags(ev, fOSLFlags);
  179.     semInt->UsingPredispatchProc(ev, fUsingPredispatchProc);
  180.     
  181.     return semInt;
  182. }
  183.  
  184. //---------------------------------------------------------------------------------------
  185. //    FW_CSemanticInterface::AcquireSOMInterface
  186. //---------------------------------------------------------------------------------------
  187.  
  188. FW_OSemanticInterface* FW_CSemanticInterface::AcquireSOMInterface(Environment* ev)
  189. {
  190.     return (FW_OSemanticInterface*)fPart->GetExtensionManager(ev)->AcquireExtension(ev, kODExtSemanticInterface, FW_kDontCreateExtension);
  191. }
  192.  
  193. //========================================================================================
  194. //  Begin Callbacks
  195. //========================================================================================
  196.  
  197. //---------------------------------------------------------------------------------------
  198. //    FW_CSemanticInterface::CallEventHandler
  199. //---------------------------------------------------------------------------------------
  200.  
  201. void FW_CSemanticInterface::CallEventHandler(Environment* ev, 
  202.                                             FW_CAppleEvent& event, 
  203.                                             FW_CAppleEvent& reply)
  204. {
  205.     // FW_DebugIdentifyPart(ev, fPart->GetLastActiveFrame(ev), FW_kRGBGreen);
  206.     
  207.     FW_CAcquiredScriptable targetObject = AcquireTargetObject(ev, event);
  208.  
  209.     AEKeyword eventClass = event.GetEventClass();
  210.     AEKeyword eventID = event.GetEventID();
  211.         
  212.     targetObject->HandleSemanticEvent(ev, fPart, eventClass, eventID, event, reply);
  213. }
  214.     
  215. //---------------------------------------------------------------------------------------
  216. //    FW_CSemanticInterface::CallCoercionHandler
  217. //---------------------------------------------------------------------------------------
  218.  
  219. void FW_CSemanticInterface::CallCoercionHandler(Environment* ev,
  220.                                                 const FW_CDesc& theDesc,
  221.                                                 ODDescType toType,
  222.                                                 FW_CDesc& theResult)
  223. {
  224. FW_UNUSED(ev);
  225.     FW_Handled handled = FW_CDescCoercionCallbacks::InvokeHandler(theDesc, toType, theResult);
  226.     if (handled == FW_kNotHandled)
  227.         FW_Failure(errAECoercionFail);
  228. }
  229.                                             
  230. //---------------------------------------------------------------------------------------
  231. //    FW_CSemanticInterface::CallPredispatchProc
  232. //---------------------------------------------------------------------------------------
  233.  
  234. void FW_CSemanticInterface::CallPredispatchProc(Environment* ev, 
  235.                                                 FW_CAppleEvent& event,
  236.                                                 FW_CAppleEvent& reply)
  237. {
  238. FW_UNUSED(ev);
  239. FW_UNUSED(event);
  240. FW_UNUSED(reply);
  241.     FW_Failure(errAEEventNotHandled);
  242. }
  243.  
  244. //---------------------------------------------------------------------------------------
  245. //    FW_CSemanticInterface::CallObjectAccessor
  246. //---------------------------------------------------------------------------------------
  247.  
  248. void FW_CSemanticInterface::CallObjectAccessor(Environment* ev,
  249.                                                 ODDescType desiredClass,
  250.                                                 ODOSLToken* container,
  251.                                                 ODDescType containerClass,
  252.                                                 ODDescType form,
  253.                                                 FW_CDesc& selectionData,
  254.                                                 ODOSLToken* value)
  255. {
  256.     // FW_DebugIdentifyPart(ev, fPart->GetLastActiveFrame(ev), FW_kRGBBlue);
  257.     
  258.     FW_CDesc containedObjectToken(GetDescFromToken(ev, value));
  259.     FW_CDesc containerToken(GetDescFromToken(ev, container));
  260.     FW_CAcquiredScriptable acquiredObject;
  261.     
  262.             // OpenDoc 1.0 doesn't handle OSLSupportFlags correctly.
  263.             // Instead of respecting our request for object marking,
  264.             // we get a container token here that is a list built
  265.             // by the OD OSL. For now, we'll simulate marking by
  266.             // building generating a collection of marked objects ourselves.
  267.             
  268.     if (containerToken.IsList() && desiredClass == cProperty)
  269.     {
  270.         ODDescType whichProperty;
  271.         
  272.         selectionData >> whichProperty;
  273.         acquiredObject = CreateCollectionFromList(ev, fPart, containerToken, whichProperty);
  274.     }
  275.     else
  276.     {
  277.         if (containerClass == cPart)
  278.         {
  279.             FW_MPartScriptable* part = GetDefaultContainer();
  280.             acquiredObject = part->AcquireObjectContainedInPart(ev, desiredClass, form, selectionData);
  281.         }
  282.         else
  283.         {
  284.             FW_MScriptable* containerObject;
  285.             
  286.             if (containerToken.IsNullDescriptor())
  287.                 containerObject = GetDefaultContainer();
  288.             else
  289.                 containerObject = ::FW_ExtractScriptableFromDesc(containerToken);
  290.         
  291.             acquiredObject = containerObject->AcquireContainedObject(ev, fPart, desiredClass, form, selectionData);
  292.         }
  293.         
  294.     }
  295.     
  296.     if (acquiredObject != NULL)
  297.         ::FW_InsertScriptableIntoDesc(acquiredObject, containedObjectToken);
  298.     else
  299.         FW_Failure(errAEEventNotHandled);
  300. }
  301.                                                     
  302. //---------------------------------------------------------------------------------------
  303. //    FW_CSemanticInterface::CallCompareProc
  304. //---------------------------------------------------------------------------------------
  305.  
  306. void FW_CSemanticInterface::CallCompareProc(Environment* ev,
  307.                                             ODDescType oper,
  308.                                             ODOSLToken* obj1,
  309.                                             ODOSLToken* obj2,
  310.                                             ODBoolean* result)
  311. {
  312.     FW_CDesc desc1(GetDescFromToken(ev, obj1));
  313.     FW_CDesc desc2(GetDescFromToken(ev, obj2));
  314.         
  315.     if (desc1.DescriptorType() == FW_kSemanticObjectTokenType)
  316.     {
  317.         FW_MScriptable* semanticObject = ::FW_ExtractScriptableFromDesc(desc1);
  318.         *result = semanticObject->CompareScriptableObjects(ev, fPart, oper, desc2);
  319.     }
  320.     else
  321.         FW_Failure(errAEEventNotHandled);
  322. }
  323.                                                     
  324. //---------------------------------------------------------------------------------------
  325. //    FW_CSemanticInterface::CallCountProc
  326. //---------------------------------------------------------------------------------------
  327. void FW_CSemanticInterface::CallCountProc(Environment* ev,
  328.                                         ODDescType desiredClass,
  329.                                         ODDescType containerClass,
  330.                                         ODOSLToken* container,
  331.                                         ODSLong* result)
  332. {
  333.     FW_CDesc containerToken(GetDescFromToken(ev, container));
  334.     
  335.     long                elementCount = 0;
  336.  
  337.     if (containerClass == cPart)
  338.     {
  339.         elementCount = GetDefaultContainer()->CountElementsInPart(ev, desiredClass);
  340.     }
  341.     else
  342.     {
  343.         FW_MScriptable*    containerObject = NULL;
  344.  
  345.         if (containerToken.IsNullDescriptor())
  346.             containerObject = GetDefaultContainer();
  347.         else
  348.             containerObject = ::FW_ExtractScriptableFromDesc(containerToken);
  349.         
  350.         elementCount = containerObject->CountElements(ev, fPart, desiredClass);
  351.     }
  352.     
  353.     *result = elementCount;
  354. }
  355.  
  356. //---------------------------------------------------------------------------------------
  357. //    FW_CSemanticInterface::CallDisposeTokenProc
  358. //---------------------------------------------------------------------------------------
  359. void FW_CSemanticInterface::CallDisposeTokenProc(Environment* ev, ODOSLToken* unneededToken)
  360. {
  361.     FW_CDesc token(GetDescFromToken(ev, unneededToken));
  362.     
  363.     if (token.DescriptorType() == FW_kSemanticObjectTokenType)
  364.     {
  365.         FW_MScriptable* scriptableObject = ::FW_ExtractScriptableFromDesc(token);
  366.         scriptableObject->ReleaseScriptable();
  367.         token.Clear();
  368.     }
  369.     else
  370.         FW_Failure(errAEEventNotHandled);
  371. }
  372.                                                         
  373. //---------------------------------------------------------------------------------------
  374. //    FW_CSemanticInterface::CallGetErrDescProc
  375. //---------------------------------------------------------------------------------------
  376. void FW_CSemanticInterface::CallGetErrDescProc(Environment* ev, ODDesc** errDesc)
  377. {
  378. FW_UNUSED(ev);
  379. FW_UNUSED(errDesc);
  380.     FW_Failure(errAEEventNotHandled);
  381. }
  382.                                                     
  383. //---------------------------------------------------------------------------------------
  384. //    FW_CSemanticInterface::CallGetMarkTokenProc
  385. //---------------------------------------------------------------------------------------
  386. void FW_CSemanticInterface::CallGetMarkTokenProc(Environment* ev,
  387.                                                 ODOSLToken* dContainerToken,
  388.                                                 ODDescType    containerClass,
  389.                                                 ODOSLToken* result)
  390. {
  391. FW_UNUSED(dContainerToken);
  392. FW_UNUSED(containerClass);
  393.     
  394.     // FW_DebugIdentifyPart(ev, fPart->GetLastActiveFrame(ev), FW_kRGBBlue);
  395.     
  396.     FW_CDesc collectionToken(GetDescFromToken(ev, result));
  397.  
  398.     FW_CAcquiredScriptable collection = FW_NEW(FW_CScriptableCollection, ());
  399.     ::FW_InsertScriptableIntoDesc(collection, collectionToken);
  400. }
  401.                                                         
  402. //---------------------------------------------------------------------------------------
  403. //    FW_CSemanticInterface::CallMarkProc
  404. //---------------------------------------------------------------------------------------
  405. void FW_CSemanticInterface::CallMarkProc(Environment* ev,
  406.                                         ODOSLToken* objectToMarkToken,
  407.                                         ODOSLToken* markingListToken,
  408.                                         ODSLong index)
  409. {
  410. FW_UNUSED(index);
  411.  
  412.     // FW_DebugIdentifyPart(ev, fPart->GetLastActiveFrame(ev), FW_kRGBRed);
  413.     
  414.     FW_CDesc objectToMarkDesc(GetDescFromToken(ev, objectToMarkToken));
  415.     FW_CDesc markingListDesc(GetDescFromToken(ev, markingListToken));
  416.     
  417.     FW_MScriptable* objectToMark = ::FW_ExtractScriptableFromDesc(objectToMarkDesc);
  418.     FW_CScriptableCollection* collection = 
  419.         FW_DYNAMIC_CAST(FW_CScriptableCollection, ::FW_ExtractScriptableFromDesc(markingListDesc));
  420.     
  421.     collection->Add(objectToMark);
  422. }
  423.     
  424. //---------------------------------------------------------------------------------------
  425. //    FW_CSemanticInterface::CallAdjustMarksProc
  426. //---------------------------------------------------------------------------------------
  427. void FW_CSemanticInterface::CallAdjustMarksProc(Environment* ev,
  428.                                                 ODSLong newStart,
  429.                                                 ODSLong newStop,
  430.                                                 ODOSLToken* markToken)
  431. {
  432.     // FW_DebugIdentifyPart(ev, fPart->GetLastActiveFrame(ev), FW_kRGBGreen);
  433.     
  434.     FW_CDesc markingListDesc(GetDescFromToken(ev, markToken));
  435.     FW_CScriptableCollection* collection = 
  436.         FW_DYNAMIC_CAST(FW_CScriptableCollection, ::FW_ExtractScriptableFromDesc(markingListDesc));
  437.     
  438.     collection->AdjustMarks(ev, newStart, newStop);
  439. }
  440.     
  441. //---------------------------------------------------------------------------------------
  442. //    FW_CSemanticInterface::GetOSLSupportFlags
  443. //---------------------------------------------------------------------------------------
  444.  
  445. ODSShort FW_CSemanticInterface::GetOSLSupportFlags(Environment* ev)
  446. {
  447. FW_UNUSED(ev);
  448.     return fOSLFlags;
  449.  
  450. //---------------------------------------------------------------------------------------
  451. //    FW_CSemanticInterface::SetOSLSupportFlags
  452. //---------------------------------------------------------------------------------------
  453.  
  454. void FW_CSemanticInterface::SetOSLSupportFlags(Environment* ev, ODSShort flags)
  455. {
  456.     fOSLFlags = flags;
  457.     
  458.     FW_OSemanticInterface* semInt = AcquireSOMInterface(ev);
  459.     if (semInt)
  460.     {
  461.         semInt->SetOSLSupportFlags(ev, flags);
  462.         semInt->Release(ev);
  463.     }
  464. }
  465.                                                     
  466. //---------------------------------------------------------------------------------------
  467. //    FW_CSemanticInterface::UsingPredispatchProc
  468. //---------------------------------------------------------------------------------------
  469.  
  470. void FW_CSemanticInterface::UsingPredispatchProc(Environment* ev, ODBoolean usingNotUsing)
  471. {
  472.     fUsingPredispatchProc = usingNotUsing;
  473.     
  474.     ODSemanticInterface* semInt = AcquireSOMInterface(ev);
  475.     if (semInt)
  476.     {
  477.         semInt->UsingPredispatchProc(ev, usingNotUsing);
  478.         semInt->Release(ev);
  479.     }
  480. }
  481.  
  482. //---------------------------------------------------------------------------------------
  483. //    FW_CSemanticInterface::CreateCollectionFromList
  484. //---------------------------------------------------------------------------------------
  485.  
  486. FW_MScriptable* FW_CSemanticInterface::CreateCollectionFromList(Environment* ev,
  487.                                                                     FW_CPart* part,
  488.                                                                     const FW_CDesc& objectList,
  489.                                                                     ODDescType whichProperty) const
  490. {
  491.     FW_ASSERT(objectList.IsList());
  492.     
  493.     // FW_DebugIdentifyPart(ev, fPart->GetLastActiveFrame(ev), FW_kRGBPurple);
  494.     
  495.     FW_CScriptableCollection* collection = FW_NEW(FW_CScriptableCollection, ());
  496.     
  497.     FW_CDesc     currentODToken;
  498.     FW_CDesc    currentToken;
  499.     long         itemsInList = objectList.GetItemCount();
  500.     
  501.     for (long index = 1; index <= itemsInList; index++)
  502.     {
  503.         currentODToken.Clear();
  504.         currentToken.Clear();
  505.         
  506.         objectList.GetDescFromList(index, currentODToken);
  507.         currentToken = GetDescFromToken(ev, currentODToken);
  508.         
  509.         FW_MScriptable* semObj = ::FW_ExtractScriptableFromDesc(currentToken);
  510.         
  511.         if (whichProperty != keyNoKey)
  512.         {
  513.             FW_CPropertyDesignator* propDesignator;
  514.  
  515.             propDesignator = FW_NEW(FW_CPropertyDesignator, (part, semObj, whichProperty));
  516.             collection->Add(propDesignator);
  517.         }
  518.         else
  519.             collection->Add(semObj);
  520.     }
  521.     return collection;
  522. }
  523.  
  524. //---------------------------------------------------------------------------------------
  525. //    FW_CSemanticInterface::GetDescFromToken
  526. //---------------------------------------------------------------------------------------
  527.  
  528. ODDesc* FW_CSemanticInterface::GetDescFromToken(Environment* ev, 
  529.                                                 ODOSLToken* token) const
  530. {
  531.     ODNameResolver* nameResolver = FW_CSession::GetNameResolver(ev);
  532.     return (nameResolver->IsODToken(ev, token) ? nameResolver->GetUserToken(ev, token) : token);
  533. }
  534.  
  535. //---------------------------------------------------------------------------------------
  536. //    FW_CSemanticInterface::AcquireTargetObject
  537. //---------------------------------------------------------------------------------------
  538.  
  539. FW_MScriptable* FW_CSemanticInterface::AcquireTargetObject(Environment* ev,
  540.                                                     FW_CAppleEvent& event)
  541. {
  542.     FW_CDesc targetObjectDesc;
  543.     FW_MScriptable* result = NULL;
  544.     
  545.     if (event.HasDataKey(keyDirectObject))
  546.     {
  547.         FW_CDesc directObjectToken;
  548.         
  549.         event.GetDataByDesc(directObjectToken, keyDirectObject);
  550.         result = AcquireScriptableFromToken(ev, directObjectToken);
  551.     }
  552.     else if (event.HasAttribute(keySubjectAttr))
  553.     {
  554.         FW_CDesc subjectDesc;
  555.         event.GetSubject(subjectDesc);
  556.         Resolve(ev, subjectDesc, targetObjectDesc);
  557.         
  558.         FW_TRY
  559.         {
  560.             result = AcquireScriptableFromToken(ev, targetObjectDesc);
  561.         }
  562.         FW_CATCH_BEGIN
  563.         FW_CATCH_EVERYTHING()
  564.         {
  565.             FW_CSession::GetNameResolver(ev)->DisposeToken(ev, targetObjectDesc);
  566.             FW_THROW_SAME();
  567.         }
  568.         FW_CATCH_END
  569.         
  570.         FW_CSession::GetNameResolver(ev)->DisposeToken(ev, targetObjectDesc);
  571.     }
  572.     else
  573.         FW_Failure(errAEEventNotHandled);
  574.     
  575.     return result;
  576. }
  577.  
  578. //---------------------------------------------------------------------------------------
  579. //    FW_CSemanticInterface::Resolve
  580. //---------------------------------------------------------------------------------------
  581.  
  582. void FW_CSemanticInterface::Resolve(Environment* ev,
  583.                                     const FW_CDesc& objectSpec,
  584.                                     FW_CDesc& odfToken,
  585.                                     ODPart* contextPart) const
  586. {
  587.     if (objectSpec.IsNullDescriptor())
  588.     {
  589.         odfToken.Clear();
  590.     }
  591.     else
  592.     {    
  593.         ODNameResolver* nameResolver = FW_CSession::GetNameResolver(ev);
  594.         
  595.         nameResolver->Resolve(ev, objectSpec, odfToken, contextPart);
  596.         odfToken.SetOwnsODData(FALSE);
  597.     }
  598. }
  599.  
  600. //---------------------------------------------------------------------------------------
  601. //    FW_CSemanticInterface::AcquireScriptableFromToken
  602. //---------------------------------------------------------------------------------------
  603.  
  604. FW_MScriptable* FW_CSemanticInterface::AcquireScriptableFromToken(Environment* ev,
  605.                                                                 const FW_CDesc& odToken) const
  606. {    
  607.     FW_MScriptable* scriptable = NULL;
  608.     FW_CDesc        odfToken = GetDescFromToken(ev, odToken);
  609.     ODDescType        tokenType = odfToken.DescriptorType();
  610.     FW_Boolean        contextIsMyPart = false;
  611.  
  612.         // The tokenType == kODStandardPartTokenType is necessary to work around
  613.         // two bugs in OpenDoc 1.1 and earlier (possibly later) releases. When
  614.         // an apple event without a direct object is received by OpenDoc, the subject
  615.         // attribute is resolved, and the event is dispatched based on the resolved
  616.         // subject attribute. Because of a bug in OpenDoc, the event might first
  617.         // be dispatched to the wrong part - sometimes the root, sometimes the
  618.         // part that contains the actual target. Whether it goes to the root or
  619.         // the containing part is a function of the specifier form used.
  620.         // The code below attempts to detect the case where an event has been
  621.         // mis-dispatched. We look for a standard ODPartToken and, if we find
  622.         // one, we call GetContextFromToke.
  623.         // There is a second bug in OpenDoc that causes the context to usually
  624.         // be wrong. Consequently, we can't really work around the first bug.
  625.         // When the contextPart is NULL, this is an indication that the event
  626.         // was first misdispatched to the shell, and is now being dispatched
  627.         // to us. We treat this as an event targeted at the part. When the
  628.         // contextPart is not NULL, we compare it against our part. Because of
  629.         // the first bug, contextPart will usually be our container when it
  630.         // should be us...we can't reliably detect this case, so we treat it
  631.         // as if it's not our event (we might actually be the container getting
  632.         // the event that is really targeted at something we contain).
  633.         
  634.         // What this means: Events without direct objects do not work and are
  635.         // not reliable in the current version of OpenDoc. Sometimes they will
  636.         // make it into the part and get handled, sometimes they won't.
  637.     if (tokenType == kODStandardPartTokenType)
  638.     {
  639.         ODPart* contextPart;
  640.         ODFrame* contextFrame;
  641.         FW_CSession::GetNameResolver(ev)->GetContextFromToken(ev, odToken, &contextPart, &contextFrame);
  642.         
  643.         if (!contextPart || (contextPart == fPart->GetODPart(ev)))
  644.             contextIsMyPart = true;
  645.     }
  646.     
  647.     if (odfToken.IsNullDescriptor() || contextIsMyPart)
  648.     {
  649.         scriptable = GetDefaultContainer();
  650.         scriptable->AcquireScriptable();
  651.     }
  652.     else if (tokenType == FW_kSemanticObjectTokenType)
  653.     {
  654.         scriptable = ::FW_ExtractScriptableFromDesc(odfToken);
  655.         scriptable->AcquireScriptable();
  656.     }
  657.     else if (odfToken.IsList())
  658.     {
  659.         scriptable = CreateCollectionFromList(ev, fPart, odfToken);
  660.     }
  661.     else
  662.         FW_Failure(errAEEventNotHandled);
  663.         
  664.     return scriptable;
  665. }
  666.  
  667. //---------------------------------------------------------------------------------------
  668. //    FW_DebugIdentifyPart:
  669. //    This utility method is for debugging semantic event handling in nested parts.
  670. //    A circle of the specified color will be briefly displayed in the top left
  671. //    corner of the first facet of the specified frame. This method does not attempt 
  672. //  to redraw or invalidate the content area obscured by the circle.
  673. //
  674. //    Note: This method may not be a permanent part of the ODF API.
  675. //---------------------------------------------------------------------------------------
  676.  
  677. void FW_DebugIdentifyPart(Environment* ev, FW_CFrame* frame, const FW_CColor& color)
  678. {
  679.     if (frame)
  680.     {
  681.         FW_CFrameFacetIterator iter(ev, frame);
  682.         FW_CViewContext vc(ev, frame, iter.First(ev), NULL);
  683.         FW_CRect rect(FW_kFixed0, FW_kFixed0, FW_IntToFixed(10), FW_IntToFixed(10));
  684.         
  685.         FW_CInk ink;
  686.         ink.SetForeColor(color);
  687.         ink.SetTransferMode(FW_kCopy);
  688.         FW_COvalShape::RenderOval(vc, rect, FW_kFill, ink);
  689.         FW_WaitFor(20);
  690.         ink.SetTransferMode(FW_kErase);
  691.         FW_COvalShape::RenderOval(vc, rect, FW_kFill, ink);
  692.     }
  693. }
  694.                                                     
  695. //========================================================================================
  696. //  End Callbacks
  697. //========================================================================================
  698.  
  699. //---------------------------------------------------------------------------------------
  700. //    FW_CSemanticInterface::PrivCreate
  701. //---------------------------------------------------------------------------------------
  702.  
  703. ODExtension* FW_CSemanticInterface::PrivCreate(Environment* ev, FW_CPart* part, const char* name, void* refCon)
  704. {
  705.     return (part->GetSemanticInterface(ev)->CreateSOMInterface(ev, part, name, refCon));        
  706. }
  707.